﻿<common:LayoutAwarePage
    x:Class="Looptribe.Moodlin8.View.CourseEventsPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Looptribe.Moodlin8.View"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:common="using:Looptribe.Moodlin8.Common"
    DataContext="{Binding CourseEvents, Source={StaticResource Locator}}"
    mc:Ignorable="d">

    <Page.Resources>
        <DataTemplate x:Key="EventTemplate">
            <Grid Height="70" Margin="2" Width="300">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <StackPanel Orientation="Horizontal">
                    <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}" Width="70" Height="70">
                        <ContentControl Template="{StaticResource DateBlockTemplate}" />
                    </Border>
                    <Border BorderThickness="1" Width="230" Height="70" BorderBrush="#FFD3D3D3" Background="{StaticResource HubListItemBackground}">
                        <StackPanel Grid.Column="1" VerticalAlignment="Top" Margin="10,0,0,0" Width="220" >
                            <!--<TextBlock Text="{Binding Id, Converter={StaticResource CourseTitleBinder}}" Style="{StaticResource TitleTextStyle}" TextWrapping="NoWrap"/>-->
                            <TextBlock Text="{Binding Name}" Style="{StaticResource SubtitleTextStyle}" TextWrapping="NoWrap"/>
                            <TextBlock Text="{Binding DateTime}" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap"/>
                        </StackPanel>
                    </Border>
                </StackPanel>
            </Grid>
        </DataTemplate>
    </Page.Resources>

    <Grid>
        <Grid x:Name="LayoutRoot" Style="{StaticResource LayoutRootStyle}">
            <Grid.Background>
                <ImageBrush ImageSource="ms-appx:///Assets/Background.png"/>
            </Grid.Background>
            <Grid.RowDefinitions>
                <RowDefinition Height="140"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <ProgressBar IsIndeterminate="True" Grid.Row="1" Visibility="{Binding IsLoading,Converter={StaticResource BooleanToVisibilityConverter}}" />

            <!-- Back button and page title -->
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
                <Grid Grid.Column="1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" MaxWidth="800"/>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock x:Name="pageTitle" Text="{Binding Course.Fullname}" Style="{StaticResource MoodleAppTitleSyle}" Margin="0,0,0,40" Grid.Column="0" TextWrapping="NoWrap" TextTrimming="WordEllipsis"/>
                    <TextBlock Text=":" Style="{StaticResource MoodleAppTitleSyle}" Margin="0,0,10,40" Grid.Column="1"/>
                    <TextBlock x:Uid="CourseParticipantsPageTitle" Text="Participants" Style="{StaticResource PageHeaderTextStyle}" Foreground="Gray" Grid.Column="2"/>
                </Grid>
            </Grid>

            <ListView Padding="116,0,116,46" Grid.Row="1" Margin="0,20,0,0" ItemsSource="{Binding Events}" ItemTemplate="{StaticResource EventTemplate}" SelectionMode="None" IsSwipeEnabled="False">
                <ListView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapGrid Orientation="Vertical" />
                    </ItemsPanelTemplate>
                </ListView.ItemsPanel>
            </ListView>

            <VisualStateManager.VisualStateGroups>

                <!-- Visual states reflect the application's view state -->
                <VisualStateGroup x:Name="ApplicationViewStates">
                    <VisualState x:Name="FullScreenLandscape"/>
                    <VisualState x:Name="Filled"/>

                    <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                    <VisualState x:Name="FullScreenPortrait">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>

                    <!-- The back button and title have different styles when snapped -->
                    <VisualState x:Name="Snapped">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
        </Grid>
    </Grid>
</common:LayoutAwarePage>